﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.Data
{
    [Serializable]
    public class BCDateDataCollection:ICloneable
    {

        double _constData = 0;
        /// <summary>
        /// 常数数据
        /// </summary>
        public double ConstData
        {
            get { return _constData; }
            set { _constData = value; }
        }

        /// <summary>
        /// 是否使用常数数据 ConstData
        /// </summary>
        public bool IsDataConst
        {
            get
            {
                return this._BCDatas.Count <= 0;
            }
        }

        List<BCDateData> _BCDatas = new List<BCDateData>();
        /// <summary>
        /// 时间段数据
        /// </summary>
        public List<BCDateData> BCDatas
        {
            get { return _BCDatas; }
            set { _BCDatas = value; }
        }


        public object Clone()
        {
            BCDateDataCollection bccollection = (BCDateDataCollection)this.MemberwiseClone();

            bccollection._BCDatas = new List<BCDateData>();

            foreach (var item in this._BCDatas)
            {
                bccollection._BCDatas.Add((BCDateData)item.Clone());
            }

            if (bccollection._BCDatas.Count > 0)
                bccollection._BCDatas[0].PreData = null;
            if (bccollection._BCDatas.Count > 1)
            {
                bccollection._BCDatas[0].AfterData = bccollection._BCDatas[1];
            }
            for (int i = 1; i < bccollection._BCDatas.Count - 1; i++)
            {
                bccollection._BCDatas[i].PreData = bccollection._BCDatas[i - 1];
                bccollection._BCDatas[i].AfterData = bccollection._BCDatas[i + 1];
            }
            if (bccollection._BCDatas.Count == 1)
            {
                bccollection._BCDatas[0].AfterData = null;
            }
            if (bccollection._BCDatas.Count > 1)
            {
                bccollection._BCDatas[bccollection._BCDatas.Count - 1].PreData = bccollection._BCDatas[bccollection._BCDatas.Count - 2];
                bccollection._BCDatas[bccollection._BCDatas.Count - 1].AfterData = null;
            }

            return bccollection;
        }
    }
}
